/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rad.Java.MotelPlus.Class;

import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.FileNotFoundException;
import java.io.Serializable;

/**
 *
 * @author rogerio
 */
public class Setting implements Serializable
{

    // <editor-fold defaultstate="collapsed" desc="Variables declaration">
    private String _company_name;
    private String _company_address;
    private String _company_phone;
    private String _apts_by_block;
    private String _cols_number;
    private String _rows_number;
    private String _file_name = "settings.jrf";
    private String _message_error;
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Get's and Set's">
    public String getAptsByBlock() {
        return _apts_by_block;
    }

    public void setAptsByBlock(String _apts_by_block) {
        this._apts_by_block = _apts_by_block;
    }

    public String getColsNumber() {
        return _cols_number;
    }

    public void setColsNumber(String _cols_number) {
        this._cols_number = _cols_number;
    }

    public String getCompanyAddress() {
        return _company_address;
    }

    public void setCompanyAddress(String _company_address) {
        this._company_address = _company_address;
    }

    public String getCompanyName() {
        return _company_name;
    }

    public void setCompanyName(String _company_name) {
        this._company_name = _company_name;
    }

    public String getCompanyPhone() {
        return _company_phone;
    }

    public void setCompanyPhone(String _company_phone) {
        this._company_phone = _company_phone;
    }

    public String getRowsNumber() {
        return _rows_number;
    }

    public void setRowsNumber(String _rows_number) {
        this._rows_number = _rows_number;
    }

    public String getFileName()
    {
        return this._file_name;
    }

    public void setFileName(String value)
    {
        this._file_name = value;
    }

    public String getErrorMessage()
    {
        return this._message_error;
    }
    // </editor-fold>



    // <editor-fold defaultstate="collapsed" desc="comment">
	public boolean writeSettings(String nameFile){
		try{
		   FileOutputStream out = new FileOutputStream(nameFile);
		   ObjectOutputStream ooOutput= null;
			try{
				ooOutput= new ObjectOutputStream(out);
				ooOutput.writeObject(this);
			}
			catch(IOException e){
				System.out.println("IO Exception writeSettings-editSetings: \n"+e);
                                _message_error = e.getMessage();
                                return false;
			}
		}
		catch(FileNotFoundException e){
			System.out.println("The file can't be created!!!");
                        _message_error = e.getMessage();
                        return false;
		}
                return true;
	}

	public boolean readSettings(String nameFile){
		Setting s = new Setting();
		ObjectInputStream oiInput= null;
		try{
			try{
			   FileInputStream in= new FileInputStream(nameFile);
				oiInput= new ObjectInputStream( in );
			}
			catch(FileNotFoundException e){
				System.out.println("File not found!");
                                _message_error = e.getMessage();
                                return false;
			}
			s= (Setting) oiInput.readObject();

			_company_name= s.getCompanyName();
			_company_address= s.getCompanyAddress();
			_company_phone= s.getCompanyPhone();
			_apts_by_block= s.getAptsByBlock();
			_cols_number= s.getColsNumber();
            _rows_number = s.getRowsNumber();
		}
		catch(Exception e){
			System.out.println("Exception readSettings-editSettings: \n"+e);
                        _message_error = e.getMessage();
                        return false;
		}
                return true;
	}
    // </editor-fold>
}
